package com.xc.h05.controller.lishenao;

import com.github.pagehelper.PageInfo;
import com.xc.h05.entity.Articletype;
import com.xc.h05.service.lishenao.ArticletypeService;
import com.xc.h05.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class ArticletypeController {
    @Autowired
    private ArticletypeService articletypeService;
    @GetMapping("/articletype")
    public R selectAll() {
        List<Articletype> articletypes = articletypeService.selectAll();
        return R.ok(articletypes);
    }

    @GetMapping("/articletypeByname")
    public R selectAllWithArticle(Articletype articletype, Integer pageNum, Integer pageSize) {
        PageInfo<Articletype> pageInfo = articletypeService.selectAllWithArticle(articletype, pageNum, pageSize);
        return R.ok(pageInfo);
    }
    @PostMapping("/addarticletype")
    public R add(@RequestBody Articletype articletype) {
        int i = articletypeService.add(articletype);
        if(i>0){
            return R.ok("添加成功");
        }else {
            return R.error();
        }
    }
    @PutMapping("updatearticletype")
    public R update(@RequestBody Articletype articletype) {
        int i = articletypeService.update(articletype);
        if(i>0){
            return R.ok("修改成功");
        }else {
            return R.error();
        }
    }
    @DeleteMapping("/deletearticletype")
    public R deleteById(Long id) {
        int i = articletypeService.deleteById(id);
        if(i>0){
            return R.ok("删除成功");
        }else {
            return R.error();
        }
    }

    @GetMapping("/selectarticletypebyId")
    public R selectByPrimaryKey(Long id) {
        Articletype articletype = articletypeService.selectByPrimaryKey(id);
        return R.ok(articletype);
    }
}
